home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / assocc1 / example.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1995-09-06  |  4.2 KB  |  149 lines

  1. VERSION 2.00
  2. Begin Form frmMain 
  3.    BorderStyle     =   1  'Fixed Single
  4.    Caption         =   "Assoc Example"
  5.    ClientHeight    =   2685
  6.    ClientLeft      =   4035
  7.    ClientTop       =   3000
  8.    ClientWidth     =   2010
  9.    Height          =   3090
  10.    Left            =   3975
  11.    LinkTopic       =   "Form1"
  12.    MaxButton       =   0   'False
  13.    MinButton       =   0   'False
  14.    ScaleHeight     =   2685
  15.    ScaleWidth      =   2010
  16.    Top             =   2655
  17.    Width           =   2130
  18.    Begin CommandButton btnExit 
  19.       Caption         =   "Exit"
  20.       Height          =   252
  21.       Left            =   1320
  22.       TabIndex        =   2
  23.       Top             =   2280
  24.       Width           =   612
  25.    End
  26.    Begin CommandButton btnAssoc 
  27.       Caption         =   "Assoc"
  28.       Height          =   372
  29.       Left            =   120
  30.       TabIndex        =   1
  31.       Top             =   2160
  32.       Width           =   852
  33.    End
  34.    Begin CommandButton btnArray 
  35.       Caption         =   "Array"
  36.       Height          =   372
  37.       Left            =   120
  38.       TabIndex        =   0
  39.       Top             =   1680
  40.       Width           =   852
  41.    End
  42.    Begin PictureBox Addrs 
  43.       Height          =   336
  44.       Left            =   1560
  45.       ScaleHeight     =   300
  46.       ScaleWidth      =   300
  47.       TabIndex        =   5
  48.       Top             =   1680
  49.       Width           =   336
  50.    End
  51.    Begin Label lblExplain2 
  52.       AutoSize        =   -1  'True
  53.       Caption         =   "The output appears in the Debug window."
  54.       Height          =   384
  55.       Left            =   120
  56.       TabIndex        =   4
  57.       Top             =   960
  58.       Width           =   1812
  59.       WordWrap        =   -1  'True
  60.    End
  61.    Begin Label lblExplain1 
  62.       AutoSize        =   -1  'True
  63.       Caption         =   "Click on Array or Assoc to load names and addresses."
  64.       Height          =   576
  65.       Left            =   120
  66.       TabIndex        =   3
  67.       Top             =   120
  68.       Width           =   1812
  69.       WordWrap        =   -1  'True
  70.    End
  71. Option Explicit
  72. Dim Surnames(1 To 100) As String, Addresses(1 To 100) As String
  73. Sub Addrs_Enumerate (Key As String, Value As String)
  74.     Debug.Print Key, Value
  75. End Sub
  76. Sub btnArray_Click ()
  77.     Call TryArray
  78. End Sub
  79. Sub btnAssoc_Click ()
  80.     Call TryAssoc
  81. End Sub
  82. Sub btnExit_Click ()
  83.     Unload frmMain
  84. End Sub
  85. Sub TryArray ()
  86.     Dim DataFile As String
  87.     Dim Surname As String, Address As String
  88.     Dim I As Integer, N As Integer
  89.     ' Set the full path for the data file
  90.     If Right$(App.Path, 1) = "\" Then
  91.     DataFile = App.Path & "ADDR.DAT"
  92.     Else
  93.     DataFile = App.Path & "\" & "ADDR.DAT"
  94.     End If
  95.     ' Read in the names and addresses
  96.     Open DataFile For Input As #1
  97.     For I = 1 To 100
  98.     If EOF(1) Then N = I - 1: Exit For
  99.     Input #1, Surname
  100.     If EOF(1) Then N = I - 1: Exit For
  101.     ' .. in case there was a blank line
  102.     Input #1, Address
  103.     Surnames(I) = Surname
  104.     Addresses(I) = Address
  105.     Next I
  106.     Close #1
  107.     ' Dump the arrays to the Debug window
  108.     Debug.Print
  109.     Debug.Print "Array ..."
  110.     For I = 1 To N
  111.     Debug.Print Surnames(I), Addresses(I)
  112.     Next I
  113. End Sub
  114. Sub TryAssoc ()
  115.     Dim DataFile As String
  116.     Dim Surname As String, Address As String
  117.     Const ASSOC_ENUMERATE = 0
  118.     ' Set the full path for the data file
  119.     If Right$(App.Path, 1) = "\" Then
  120.     DataFile = App.Path & "ADDR.DAT"
  121.     Else
  122.     DataFile = App.Path & "\" & "ADDR.DAT"
  123.     End If
  124.     ' Read in the names and addresses
  125.     Open DataFile For Input As #1
  126.     Do Until EOF(1)
  127.     Input #1, Surname
  128.     If EOF(1) Then Exit Do
  129.     ' .. in case there was a blank line
  130.     Input #1, Address
  131.     Addrs.Key = Surname
  132.     Addrs.Value = Address
  133.     Loop
  134.     Close #1
  135.     ' Dump the arrays to the Debug window
  136.     Debug.Print
  137.     Debug.Print "Assoc ..."
  138.     Addrs.Key = ""
  139.     Do
  140.     Addrs.Key = Addrs.NextKey
  141.     If Addrs.Key = "" Then Exit Do
  142.     Debug.Print Addrs.Key, Addrs.Value
  143.     Loop
  144.     ' Now dump them again using the Enumerate event
  145.     Debug.Print
  146.     Debug.Print "Assoc using Enumerate ..."
  147.     Addrs.Action = ASSOC_ENUMERATE
  148. End Sub
  149.